import { Injectable }    from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class AdminService {
    private headers = new Headers({'Content-Type': 'application/json'});
    private AdminUrl = 'api/admin/';  // URL to web api
    constructor(private http: Http) { }
    login(admin:any): Promise<any> {
        return this.http
            .post(this.AdminUrl, admin, {headers: this.headers})
            .toPromise()
            .then(res => res.json().data)
            .catch(this.handleError);
    }
    private handleError(error: any): Promise<any> {
        console.error('An error occurred', error);
        return Promise.reject(error.message || error);
    }
}